package route

import (
	"time"

	"gitee.com/jiebaiyou/formflow/api/controller"
	"gitee.com/jiebaiyou/formflow/bootstrap"
	"gitee.com/jiebaiyou/formflow/pkg/storage/redis"
	"gitee.com/jiebaiyou/formflow/pkg/storage/sqlite"
	"gitee.com/jiebaiyou/formflow/repository"
	"gitee.com/jiebaiyou/formflow/service"
	"github.com/gin-gonic/gin"
)

// NewLoginRouter 创建并配置登录相关的API路由
func NewLoginRouter(env *bootstrap.Config, timeout time.Duration, db sqlite.DB, cache redis.Database, group *gin.RouterGroup) {
	// 创建用户仓库实例, 用于数据库操作
	ur := repository.NewUserRepository(db, cache)
	// 创建登录服务实例, 用于业务逻辑处理
	ls := service.NewLoginService(ur, timeout)
	// 创建登录控制器, 注入相关依赖
	lc := &controller.LoginController{
		LoginService: ls,
		Env:          env,
	}

	// 处理用户登录请求
	group.POST("/login", lc.Login)
}
